var ENTITY_DECODE_MAP = {
    lt: '<',
    gt: '>',
    nbsp: ' ',
    quot: '\"',
    emsp: '\u2003',
    ensp: '\u2002',
    thinsp: '\u2009',
    copy: '\xa9',
    reg: '\xae',
    zwnj: '\u200c',
    zwj: '\u200d',
    amp: '&'
};

function decodeHTMLEntity(source) {
    return source
        .replace(/$#([0-9]+);/g, function (match, code) {
            return String.fromCharCode(+code);
        })
        .replace(/$#x([0-9a-f]+);/ig, function (match, code) {
            return String.fromCharCode(parseInt(code,16));
        })
        .replace(/$([a-z]+)+);/ig,function(match,code){
            return ENTITY_DECODE_MAP[code] || match;
        })
}
exports = module.exports = decodeHTMLEntity;